/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2007 Intel Corporation. All Rights Reserved.
//
//
*/

#ifndef __UMC_AVS_SPLITTER_BUFFER_H
#define __UMC_AVS_SPLITTER_BUFFER_H

#include "umc_sample_buffer_ex.h"
#include "umc_start_code_array.h"

namespace UMC
{

class AVSSampleBuffer : public MediaBuffer
{
public:
    // Default constructor
    AVSSampleBuffer(void);
    // Destructor
    virtual
    ~AVSSampleBuffer(void);

    // Initialize the buffer
    virtual
    Status Init(MediaReceiverParams *pParams);

    // Lock input buffer
    virtual
    Status LockInputBuffer(MediaData *pDst);
    // Unlock input buffer
    virtual
    Status UnLockInputBuffer(MediaData *pDst, Status StreamStatus = UMC_OK);

    // Lock output buffer
    virtual
    Status LockOutputBuffer(MediaData *pSrc);
    // Unlock output buffer
    virtual
    Status UnLockOutputBuffer(MediaData *pSrc);

    // Release object
    virtual
    Status Close(void);

    // Stop the object
    Status Stop(void) {return UMC_OK;}

protected:
    // Collect start codes & organize frames
    void CollectStartCodes(size_t nSourceSize);
    // Move collected data from the temporal buffer to the destination buffer
    Status MoveCollectedSample(Status streamStatus);
    // Get number of NAL units in the collected sample
    Ipp32s GetNALUnitsNumber(void);
    // Skip info about given number of start codes
    void SkipStartCodes(Ipp32s numCodes);

    SampleBufferEx m_mainBuffer;                                // (SampleBuffer) main working buffer
    MediaBufferParams m_bufferParams;                           // (MediaBufferParams) a copy of the buffer parameter(s)

    Ipp8u *m_pbBuffer;                                          // (Ipp8u *) pointer to the temporal buffer
    size_t m_nBufferSize;                                       // (size_t) size of the allocted buffer with being collected sample
    size_t m_nInputSize;                                        // (size_t) size of the minimal input portion

    Ipp8u *m_pbSample;                                          // (Ipp8u *) pointer to the current being collected sample
    Ipp8u *m_pbSampleEnd;                                       // (Ipp8u *) pointer to the end of being collected sample

    StartCodeArray m_startCodes;                                // (StartCodeArray) array of start codes
    Ipp32s m_iNumberOfStartCodes;                               // (Ipp32s) number of collected start codes

    bool m_bFoundSequenceHeader;                                // (bool) sequence header has been found

    MediaData m_latestSample;                                   // (MediaData) latest media sample
};

} // namespace UMC

#endif // __UMC_AVS_SPLITTER_BUFFER_H
